<link rel="stylesheet" href="assets/store/css/goods.css?v=<?= $version ?>">
<link rel="stylesheet" href="assets/common/plugins/umeditor/themes/default/css/umeditor.css">
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <input type="hidden" name="contents[lesson_id]" value="<?= $lessonid ?>">
                    <input type="hidden" name="contents[type]" value="<?= $type ?>">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">基本信息</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">内容标题 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="contents[name]"
                                           value="" placeholder="请输入标题" required>
                                </div>
                            </div>
                            <div class="am-form-group " id="image-list">
                                <div class="imagesdiv">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">图片 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <div class="am-form-file">
                                            <div class="am-form-file">
                                                <button type="button"
                                                        class="upload-file am-btn am-btn-secondary am-radius">
                                                    <i class="am-icon-cloud-upload"></i> 选择图片
                                                </button>
                                                <div class="uploader-list am-cf"></div>
                                            </div>
                                            <div class="help-block am-margin-top-sm">
                                                <small class="am-margin-left-xs">
                                                    *点击对应的图片添加对应的音频文件
                                                </small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">排序</div>
                            </div>


                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">分类排序 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="contents[sort]"
                                           value="100" required>
                                    <small>数字越小越靠前</small>
                                </div>
                            </div>

                            <!-- 表单提交按钮 -->
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>

                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 图片文件列表模板 -->
{{include file="layouts/_template/tpl_file_item" /}}

<!-- 文件库弹窗 -->
{{include file="layouts/_template/file_library" /}}


<script src="assets/common/js/vue.min.js"></script>
<script src="assets/common/js/ddsort.js"></script>
<script src="assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="assets/common/plugins/umeditor/umeditor.min.js"></script>
<script src="assets/store/js/goods.spec.js?v=<?= $version ?>"></script>
<script>

    $(function () {
        /**
         * 表单验证提交
         * @type {*}
         */

        $('.upload-file').selectImagesAudio({
            name: 'goods[images][]'
            , multiple: true
            ,limit:100
        });

        // 图片列表拖动
        $('.uploader-list').DDSort({
            target: '.file-item',
            delay: 100, // 延时处理，默认为 50 ms，防止手抖点击 A 链接无效
            floatStyle: {
                'border': '1px solid #ccc',
                'background-color': '#fff'
            }
        });

        $('#my-form').superForm({
            // 获取图片及音频数据
            buildData: function () {
                var $_data = [];
                //获取数据并整理
                $('.file-item').each(function (index,element) {
                    var _this = $(this);
                    var _audio = _this.find('.audios');
                    var _audiosrc = _audio.find('audio').attr('src')?_audio.find('audio').attr('src'):'';
                    var _audioid = _audio.find('input').attr('value')?_audio.find('input').attr('value'):'';
                    var _image = {'src':_this.find('img').attr('src'),'id':_this.find('input').attr('value'),'audiosrc':_audiosrc ,'audioid': _audioid};
                    $_data.push(_image);
                });
                return {
                    data: $_data
                };
            },
        });
    });
</script>
